package me.hyman.testcustomview.itemTouchHelper.dragOnly;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;

import java.util.ArrayList;
import java.util.List;

import me.hyman.testcustomview.R;
import me.hyman.testcustomview.itemTouchHelper.helper.ItemTouchHelperCallback;

public class DragOnlyActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drag_only);

        init();
    }

    private void init() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

        List<String> items = new ArrayList<>();
        for(int i=0; i<10; i++) {
            items.add("item " + i);
        }

        GridLayoutManager manager = new GridLayoutManager(this, 2);
        recyclerView.setLayoutManager(manager);

        ItemTouchHelperCallback callback = new ItemTouchHelperCallback() {
            @Override
            public boolean isLongPressDragEnabled() {
                return true;
            }
        };

        ItemTouchHelper helper = new ItemTouchHelper(callback);
        helper.attachToRecyclerView(recyclerView);

        DragAdapter dragAdapter = new DragAdapter(DragOnlyActivity.this, items);
        recyclerView.setAdapter(dragAdapter);
    }
}
